<?php 
$perfil = "admin";

require_once  '../header.php';
require_once   '../sec.php';
$id_segmento = $_REQUEST['id_segmento'];
if($id_segmento != ""){
	$Segmento = dbManager::getEntityByPrimaryKey(new Segmento() , $id_segmento);
}

?>
 <script>
 $(function(){
	 	$("#formSegmento").validationEngine();
	 	 $("#salvar").click(function(){
		 	 if($("#formSegmento").validationEngine('validate') ){
				var dados = $("#formSegmento").serialize();
		 	 	$.ajax({
					  url: "/ajax/ajaxDispatcher.php?classe=segmentoBusiness&metodo=persistSegmento",
					  data: dados,
					}).done(function(response) {
						console.log(response)
					   	if(response != false){
					   		alert('Segmento salvo com sucesso!');
					   		window.location = 'segmento.php';
						}else{
							alert('Erro salvar segmento.');
						}
					});
		 	 }
		 });
 });
 </script>
 
 <div class='titulo'>
Cadastro de Segmento
 </div>
 <form id='formSegmento'>
	 <div class="col">
		 <label for='nm_segmento'>Nome</label>
		 <input type='text' id='nm_segmento' class="validate[required]"  value='<?=$Segmento->nm_segmento;?>' name='nm_segmento'>
	 </div>
	 <a href="#" class='btn' id='salvar'>Salvar</a>
	 
	 <a href="segmento.php" class='btn_voltar' id='voltar' style='margin-right: 20px;'>Voltar</a>
	 
	 <div class='clear'></div>
	 <input type='hidden' name='id_segmento' value='<?=$Segmento->id_segmento;?>'>
 </form>
 
 

 
<?php require_once '../rodape.php';?>